using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using CPXamarinPortable;

namespace CPXamarin
{
    public class CustomListProfileAdapter : BaseAdapter<List<KeyValuePair<string, string>>>
    {
        private Context mContext;
        private List<KeyValuePair<string, string>> myProfileList;
        public CustomListProfileAdapter(Context context, List<KeyValuePair<string, string>> myProfileList)
        {
            this.myProfileList = myProfileList;
            this.mContext = context;
        }

        public override int Count
        {
            get { return myProfileList.Count; }
        }

        public override Java.Lang.Object GetItem(int position)
        {
            return position;
        }


        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                LayoutInflater lv = (LayoutInflater)mContext.GetSystemService(Context.LayoutInflaterService);
                row = lv.Inflate(Resource.Layout.ProfileListView,null);
            }

            var key = row.FindViewById<TextView>(Resource.Id.Key);
            key.Text = myProfileList[position].Key;

            var value = row.FindViewById<TextView>(Resource.Id.Value);
            value.Text = myProfileList[position].Value;
            return row;
        }

        public override List<KeyValuePair<string, string>> this[int position]
        {
            get { return null; }
        }



        public override long GetItemId(int position)
        {
            return position;
        }
    }
}